package org.catj.entity;

public abstract class AttributeScale {
    public int MAX = 5000;
    public abstract int[] getRange();
    public abstract int getLowerLimit();
    public float getRank(int value) {
        double scoresLessThan = 0;
        double rank;
        for (int i = 0; i < getRange().length; i++) {
            if (value > getRange()[i])
                scoresLessThan++;
        }
        rank = scoresLessThan / getRange().length * 100;
        int lower = getLowerLimit();
        int upper = MAX;
        if(scoresLessThan > 0 && scoresLessThan < getRange().length){
            lower = getRange()[(int)scoresLessThan - 1];
            upper = getRange()[(int)scoresLessThan];
        }
        else if(scoresLessThan == 0){
            upper = getRange()[(int)scoresLessThan];
        }
        else if(scoresLessThan >= getRange().length){
            lower = getRange()[(int)scoresLessThan - 1];
        }
        double percentage = 1d / getRange().length;
        double plusPercent = ((value - lower) * (percentage / (upper - lower))) * 100;
        return (float) (plusPercent + rank);
    }

}
